Windows Imaging Component


Windows Imaging Component

It allows processing images in different formats, including: BMP, JPG, GIF, PNG, and TIFF.
Esta permite procesar imágenes en distintos formatos, incluyendo: BMP, JPG, GIF, PNG y TIFF.

Problem 1
Cree a Wintempla Window applicaction called DisplayReady to test Windows Imaging Component. For this exercise you need a JPG file (place the file where the source, *.cpp, files are). After creating the project, open Wintempla, double click anywhere in the editor and check the Paint event in the event tab.
Cree una aplicación de Ventana usando Wintempla llamada DisplayReady. Para este ejercicio usted necesita una imagen de JPG (coloque el archivo donde los archivos fuente, *.cpp, se encuentran.) Después de crear el proyecto, abra Wintempla, haga clic doble en donde en el editor y marque el evento de Paint en la pestaña de Eventos.

Window_Paint

DisplayReadyRun

Step A
Add at the end of the stdafx.h file the following code.
Agregue al final del archivo stdafx.h el código siguiente.

stdafx.h
. . .
//______________________________________________________________ Windows Imaging Component
#include <wincodec.h>
#include <WTypes.h>
#pragma comment (lib, "Windowscodecs.lib")
_COM_SMARTPTR_TYPEDEF(IWICImagingFactory, IID_IWICImagingFactory);
_COM_SMARTPTR_TYPEDEF(IWICBitmapDecoder, __uuidof(IWICBitmapDecoder));
_COM_SMARTPTR_TYPEDEF(IWICBitmapFrameDecode, __uuidof(IWICBitmapFrameDecode));
_COM_SMARTPTR_TYPEDEF(IWICFormatConverter, __uuidof(IWICFormatConverter));
_COM_SMARTPTR_TYPEDEF(IWICBitmapFrameDecode, __uuidof(IWICBitmapFrameDecode));


Step B
Edit the files DisplayReady.h and DisplayReady.cpp as shown.
Edite los archivos DisplayReady.h y DisplayReady.cpp como se muestra.

DisplayReady.h
#pragma once //______________________________________ DisplayReady.h
#include "Resource.h"
class DisplayReady: public Win::Window
{
public:
     DisplayReady()
     {
          ::CoInitialize(NULL);
     }
     ~DisplayReady()
     {
          ::CoUninitialize();
     }
     CG::DIBitmap bitmap;
     . . .
};


DisplayReady.cpp
. . .
void DisplayReady::Window_Open(Win::Event& e)
{
     HRESULT hr = S_OK;
     IWICImagingFactoryPtr imagingFactory;
     IWICBitmapDecoderPtr bitmapDecoder;
     IWICFormatConverterPtr formatConverter;
     IWICBitmapFrameDecodePtr bitmapFrameDecode;
     unsigned int image_width = 0;
     unsigned int image_height = 0;

     Com::Exception ex;
     try
     {
          //_____________________________________________________________________ 1. imagingFactory.CreateInstance
          hr = imagingFactory.CreateInstance(CLSID_WICImagingFactory, (IUnknown*)&imagingFactory, CLSCTX_INPROC_SERVER);
          ex.ok(L"imagingFactory.CreateInstance", hr);
          if (imagingFactory == nullptr) ex.ThrowNullPointer(L"imagingFactory");
          //_____________________________________________________________________ 2. imagingFactory->CreateFormatConverter
          hr = imagingFactory->CreateFormatConverter(&formatConverter);
          ex.ok(L"imagingFactory->CreateFormatConverter", hr);
          //_____________________________________________________________________ 3. imagingFactory.CreateDecoderFromFilename
          hr = imagingFactory->CreateDecoderFromFilename(L"arquimedes.jpg", NULL, GENERIC_READ, WICDecodeMetadataCacheOnLoad, &bitmapDecoder);
          ex.ok(L"imagingFactory->CreateDecoderFromFilename", hr);
          //_____________________________________________________________________ 4. bitmapDecoder->GetFrame
          hr = bitmapDecoder->GetFrame(0, &bitmapFrameDecode);
          ex.ok(L"bitmapDecoder->GetFrame", hr);
          //_____________________________________________________________________ 5. formatConverter->Initialize
          hr = formatConverter->Initialize(bitmapFrameDecode, GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeNone, NULL, 0, WICBitmapPaletteTypeCustom);
          ex.ok(L"formatConverter->Initialize", hr);
          //_____________________________________________________________________ 6. bitmapFrameDecode->GetSize
          hr = bitmapFrameDecode->GetSize(&image_width, &image_height);
          ex.ok(L"bitmapFrameDecode->GetSize", hr);
          //_____________________________________________________________________7. Create the bitmap
          if (bitmap.Create(24, 0, image_width, image_height, false) == false)
          {
               this->MessageBox(L"Unable to create bitmap", L"DisplayReady", MB_OK | MB_ICONERROR);
               return;
          }
          //_____________________________________________________________________ 8. bitmapFrameDecode->CopyPixels
          hr = bitmapFrameDecode->CopyPixels(NULL, (UINT)bitmap.GetBytesRowSize(), bitmap.GetBitsByteCount(), bitmap.GetBits());
          ex.ok(L"bitmapFrameDecode->GetSize", hr);
     }
     catch(Com::Exception& excep)
     {
          excep.Display(hWnd, L"DisplayReady");
     }
}


void DisplayReady::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);
     gdi.DrawBitmap(bitmap, 0, 0);
}


© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home